package com.iwhalecloud.bss.kite.cucc.web.controller.order;

import com.iwhalecloud.bss.kite.client.dto.DataResult;
import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.cucc.client.api.order.IDiscountInfoService;
import com.iwhalecloud.bss.kite.cucc.client.dto.order.KiteCartFindoopOrderReqDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.order.KiteCartFindoopOrderRspDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.order.KiteFindoopOrderDTO;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.DiscountVO;
import com.iwhalecloud.bss.kite.manager.transaction.KiteTransactional;
import com.iwhalecloud.bss.kite.web.context.KiteWebContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/discountInfo")
@Api(tags = {
    "/discountInfo - 折扣审批信息"
})
public class DiscountInfoController {

    @Autowired
    private IDiscountInfoService discountInfoService;

    @KiteTransactional
    @ApiOperation(value = "添加上传折扣审批附件信息", notes = "添加上传折扣审批附件信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "sceneInstId", value = "场景标识", required = true),
        @ApiImplicitParam(name = "offerInstId", value = "销售品实例标识", required = true),
        @ApiImplicitParam(name = "discountsJson", value = "折扣审批信息", required = true),
    })
    @PutMapping("/addDiscountInfo")
    public DataResult<List<DiscountVO>> addDiscountInfo(@RequestParam String sceneInstId, @RequestParam String offerInstId,
        @RequestParam String discountsJson) {
        return ErrorConsts.SUCCESS.getResult(discountInfoService.addDiscountInfo(sceneInstId, KiteWebContext.getContext().getCustId(), offerInstId, discountsJson));
    }

    @KiteTransactional
    @ApiOperation(value = "删除折扣审批附件信息", notes = "删除折扣审批附件信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "sceneInstId", value = "场景标识", required = true),
        @ApiImplicitParam(name = "offerInstId", value = "销售品实例标识", required = true),
        @ApiImplicitParam(name = "discountInstId", value = "折扣审批标识", required = true)
    })
    @PutMapping("/deleteDiscountInfo")
    public DataResult<List<DiscountVO>> deleteDiscountInfo(@RequestParam String sceneInstId, @RequestParam String offerInstId,
        @RequestParam String discountInstId) {
        return ErrorConsts.SUCCESS.getResult(discountInfoService.deleteDiscountInfo(sceneInstId, KiteWebContext.getContext().getCustId(), offerInstId, discountInstId));
    }

    @KiteTransactional
    @ApiOperation(value = "录入折扣审批信息", notes = "录入折扣审批信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "sceneInstId", value = "场景标识", required = true),
        @ApiImplicitParam(name = "discountJson", value = "折扣审批录入信息", required = true)
    })
    @PutMapping("/entryDiscountInfo")
    public DataResult<List<DiscountVO>> entryDiscountInfo(@RequestParam String sceneInstId, @RequestParam String discountJson) {
        return ErrorConsts.SUCCESS.getResult(discountInfoService.entryDiscountInfo(sceneInstId, KiteWebContext.getContext().getCustId(), null, discountJson));
    }

    @KiteTransactional
    @ApiOperation(value = "获取折扣审批详情信息", notes = "获取折扣审批详情信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "sceneInstId", value = "场景标识", required = true),
        @ApiImplicitParam(name = "offerInstId", value = "销售品实例标识", required = true),
        @ApiImplicitParam(name = "discountJson", value = "折扣审批标识", required = true)
    })
    @GetMapping("/getDiscountInfoDetails")
    public DataResult<List<DiscountVO>> getDiscountInfoDetails(String sceneInstId, @RequestParam String offerInstId, String discountInstId) {
        return ErrorConsts.SUCCESS.getResult(discountInfoService.getDiscountInfoDetails(sceneInstId, KiteWebContext.getContext().getCustId(), offerInstId, discountInstId));
    }

    @KiteTransactional
    @ApiOperation(value = "查询oop折扣申请单")
    @PostMapping("/findoopOrder")
    public DataResult<KiteCartFindoopOrderRspDTO> queryFindoopOrder(@RequestBody KiteCartFindoopOrderReqDTO reqDTO) {
        return ErrorConsts.SUCCESS.getResult(discountInfoService.queryFindoopOrder(reqDTO));
    }

    @KiteTransactional
    @ApiOperation(value = "录入折扣审批信息", notes = "录入折扣审批信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "sceneInstId", value = "场景标识", required = true),
        @ApiImplicitParam(name = "discountJson", value = "折扣审批录入信息", required = true)
    })
    @PutMapping("/finDoopentryDiscountInfo")
    public DataResult<List<DiscountVO>> finDoopentryDiscountInfo(@RequestParam String sceneInstId, @RequestParam String discountJson) {
        return ErrorConsts.SUCCESS.getResult(discountInfoService.finDoopentryDiscountInfo(sceneInstId, KiteWebContext.getContext().getCustId(), null, discountJson));
    }
}
